{include file="inc/top"}
<!-- 左边导航栏包含 -->
{include file="inc/sidebar"}
<!-- 内容部分 -->
 <div id="dcMain">
   <!-- 当前位置 -->
<div id="urHere">DouPHP 管理中心<b>></b><strong>添加文章</strong> </div>   <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
            <h3><a href="{url{'News/newsList'}" class="actionBtn">文章列表</a>添加文章</h3>
    <form action="{url{'News/addNews'}" method="post" enctype="multipart/form-data">
     <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
      <tr>
       <td width="90" align="right">文章名称</td>
       <td>
        <input type="text" name="title" value="{$res.title}" size="80" class="inpMain" />
       </td>
      </tr>
      <tr>
       <td align="right">文章分类</td>
       <td>
        <select name="cat_id">
         {volist name="cat" id="vo"}
         <option value="{$vo.id}" {if condition="$vo.id==$res.cat_id"} selected {/if}> {$vo.name}</option>
          {/volist}
         <td>
      </tr>
            <tr>
       <td align="right" valign="top">文章描述</td>
       <td>
        <!-- KindEditor -->
        <link rel="stylesheet" href="__JS__/kindeditor/themes/default/default.css" />
			<link rel="stylesheet" href="__JS__/kindeditor/plugins/code/prettify.css" />
			<script charset="utf-8" src="__JS__/kindeditor/kindeditor.js"></script>
			<script charset="utf-8" src="__JS__/kindeditor/lang/zh_CN.js"></script>
			<script charset="utf-8" src="__JS__/kindeditor/plugins/code/prettify.js"></script>
        <script>
					KindEditor.ready(function(K) {
						var editor1 = K.create('textarea[name="content"]', {
							cssPath : '../plugins/code/prettify.css',
							uploadJson : '../php/upload_json.php',
							fileManagerJson : '../php/file_manager_json.php',
							allowFileManager : true,
							afterCreate : function() {
								var self = this;
								K.ctrl(document, 13, function() {
									self.sync();
									K('form[name=example]')[0].submit();
								});
								K.ctrl(self.edit.doc, 13, function() {
									self.sync();
									K('form[name=example]')[0].submit();
								});
							}
						});
						prettyPrint();
					});
			</script>
        <!-- /KindEditor -->
        <textarea id="content" name="content" style="width:780px;height:400px;" class="textArea">{$res.content}</textarea>
       </td>
      </tr>
      <tr>
       <td align="right">缩略图</td>
       <td>
        <input type="text" name="image" id="image" class="inpMain" value="{$res.image}" size="50"  style="float: left;width: 320px;">
        <input type="file" name="thumb_image" size="38" class="inpFlie" id="thumb_image" style="float:left;width: 0;height: 0;opacity: 0;z-index: -1;" />
        <button class="btn" id="select_img">选择图片</button><div id="img_show"></div>
        </td>
      </tr>
      <tr>
       <td align="right">关键字</td>
       <td>
        <input type="text" name="keywords" value="{$res.keywords}" size="50" class="inpMain" />
       </td>
      </tr>
      <tr>
       <td align="right">简单描述</td>
       <td>
        <input type="text" name="description" value="{$res.description}" size="50" class="inpMain" />
       </td>
      </tr>
      <tr>
       <td></td>
       <td>
        <input type="hidden" name="id" value="{$res.id}">
        <input name="submit" class="btn" type="submit" value="提交" />
       </td>
      </tr>
     </table>
    </form>
       </div>
 </div>
 <div class="clear"></div>
        <script type="text/javascript">
            $(function () {
                $("#select_img").click(function () {
                        $("#thumb_image").click();
                        return false;
                }
                );
                $("#thumb_image").change(
                    function () {
                        //console.log($('#thumb_image').val());
                        // FormData对象，来发送二进制文件。
                        var formdata = new FormData();
                        formdata.append("myfile",document.getElementById('thumb_image').files[0]);
                        $.ajax({
                            type:"POST",
                            url:"{:url('News/addNewsPic')}",
                            data: formdata,
                            contentType:false,
                            processData:false,
                            dataType:'json',
                            success:function (data) {
                                //alert("图片上传成功！");
                                //console.log(data);
                                //$("#image").val(data);
                                $("#img_show").html("<img src='__IMG__/uploads/"+data+"' width='200px'>");
                            },
                            error:function () {
                                //alert("上传失败！");
                            }
                        })
                    }
                )
            })
        </script>

       <!--底部包含-->
       {include file="inc/footer"}